package com.yonyou.pmclouds.safeinspection.process;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.inspectitem.entity.InspectItemBillStatusConst;
import com.yonyou.pmclouds.inspectitem.entity.InspectItemVO;
import com.yonyou.pmclouds.safeinspection.entity.SafeInspectionVO;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author 徐老板
 * @date 2020/4/24   9:23
 */
@Component
public class CountRateProcess implements SingleProcessor<SafeInspectionVO> {



    @Override
    public void process(SafeInspectionVO vo, SafeInspectionVO orig) throws BusinessException {
        if (vo!=null && !ArrayUtils.isEmpty(vo.getInspectItemVOS())){
            InspectItemVO[] inspectItemVOS = vo.getInspectItemVOS();
            double total=0; double pass =0;
            for (InspectItemVO inspectItemVO : inspectItemVOS) {
                if (InspectItemBillStatusConst.BILLSTATUS_NOT_FIT!=inspectItemVO.getBillstatus()){
                    ++total;
                }
                if (InspectItemBillStatusConst.BILLSTATUS_PASS==inspectItemVO.getBillstatus()){
                    ++pass;
                }
            }
            //计算通过率
            BigDecimal passRate = new BigDecimal(0);
            if (total>0){
                passRate = BigDecimal.valueOf((pass/total) * 100).setScale(2, BigDecimal.ROUND_HALF_DOWN);
            }
            vo.setPassRate(passRate);
//            System.err.println("======================"+vo+"======================");
        }
    }
}
